package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "购物车接口")
@Slf4j
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @ApiOperation("添加购物车")
    @RequestMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("添加购物车:{}", shoppingCartDTO);
        shoppingCartService.add(shoppingCartDTO);

        return Result.success();
    }

    @ApiOperation("购物车列表")
    @RequestMapping("/list")
    public Result<List<ShoppingCart>> list() {
        log.info("购物车列表");
        List<ShoppingCart> list = shoppingCartService.list();

        return Result.success(list);
    }

    @ApiOperation("删除购物车")
    @RequestMapping("/sub")
    public Result delete(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("删除购物车:{}", shoppingCartDTO);
        shoppingCartService.delete(shoppingCartDTO);

        return Result.success();
    }

    @ApiOperation("清空购物车")
    @RequestMapping("/clean")
    public Result clear() {
        log.info("清空购物车");
        shoppingCartService.clear();

        return Result.success();
    }




}
